//
//  DeleteAccountPage.swift
//  Casecord
//
//  Created by baozi on 2024/1/10.
//

import SwiftUI

struct DeleteAccountPage: View {
    @State private var showCheck: Bool = false
    var body: some View {
        ZStack {
            ScrollView {
                VStack  {
                    Text("After submitting an account deletion request, you will not be able to log in for 7 days. If you log in during this period, the account deletion request will be canceled.")
                        .font(.system(size: 18))
                        .foregroundStyle(Theme.color.primaryBackgroundColor)
                        .paddingBottom(100)
                        .paddingHorizontal(15)
                        .paddingTop(15)
                    
                    HStack {
                        Spacer()
                        Button(action: {
                            withAnimation {
                                showCheck = true
                            }
                        }, label: {
                            Text("Delete")
                                .font(Theme.font.title)
                                .foregroundColor(.white)
                                .paddingHorizontal(20)
                                .frame(height: 40)
                                .withCapsuleBg(colors: [Theme.color.primaryBackgroundColor])
                                
                        })
                        Spacer()
                    }
                    .paddingHorizontal(40)
                }
                .paddingBottom(30)
            }
            .setCustomNav(title: "Delete Account")
            
            if showCheck {
                VStack {
                    Text("Alert")
                        .foregroundStyle(.red)
                        .font(.system(size: 20))
                        .fontWeight(.bold)
                    Text("After account cancellation, it cannot be restored. Are you sure to delete it")
                        .foregroundStyle(.red)
                        .font(.system(size: 16))
                        .fontWeight(.bold)
                        .paddingBottom(20)
                    
                    HStack (spacing: 15) {
                        Button(action: {
                            withAnimation(.linear(duration: 1)) {
                                showCheck = false
                            }
                        }, label: {
                            Text("Think again")
                                .foregroundStyle(.black)
                                .frame(width: 100)
                                .paddingVerticol(10)
                                .background(.white)
                                .clipShape(RoundedRectangle(cornerRadius: 8))
                                .shadow(color: .black.opacity(0.2), radius: 6)
                        })
                        Button(action: {
                            withAnimation(.linear(duration: 1)) {
                                showCheck = false
                            }
                            QueueMain.async(deadline: .now() + 1) {
                                ToastManager.show(text: "Apply Delete Success")
                                UserService.shared.logout()
                            }
                        }, label: {
                            Text("Confirm")
                                .foregroundStyle(Theme.color.title)
                                .frame(width: 100)
                                .paddingVerticol(10)
                                .background(.red)
                                .clipShape(RoundedRectangle(cornerRadius: 8))
                        })
                    }
                }
                .makeAlert()
                .zIndex(1)
            }
        }

    }
}

#Preview {
    DeleteAccountPage()
}
